package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsEvaluationAgency;
import com.ruoyi.system.domain.news.query.NewsEvaluationAgencyQuery;
import com.ruoyi.system.domain.news.vo.NewsEvaluationAgencyVo;
import com.ruoyi.system.service.news.NewsEvaluationAgencyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsEvaluationAgency")
@Api(value = "newsEvaluationAgencyApiController", tags  = "测评机构Api")
public class NewsEvaluationAgencyApiController extends BaseController {

	@Resource
	private NewsEvaluationAgencyService newsEvaluationAgencyService;

	@ApiOperation(value = "获取单个测评机构信息", notes = "获取单个测评机构信息")
	@GetMapping("/getById")
	public R<NewsEvaluationAgency> getById(@RequestParam(value = "id") Long id) {
		NewsEvaluationAgencyQuery newsEvaluationAgencyQuery = new NewsEvaluationAgencyQuery();
		newsEvaluationAgencyQuery.setId(id);
		List<NewsEvaluationAgencyVo> newsEvaluationAgencyList = newsEvaluationAgencyService.getNewsEvaluationAgencyList(newsEvaluationAgencyQuery);
		if (newsEvaluationAgencyList!=null&&newsEvaluationAgencyList.size()>0) {
			return R.ok(newsEvaluationAgencyList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取测评机构信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsEvaluationAgencyVo>> list(@RequestBody NewsEvaluationAgencyQuery newsEvaluationAgencyQuery) {
        newsEvaluationAgencyQuery.setIsEnable("1");
		List<NewsEvaluationAgencyVo> newsEvaluationAgencyList = newsEvaluationAgencyService.getNewsEvaluationAgencyList(newsEvaluationAgencyQuery);
		return R.ok(new PageInfo<>(newsEvaluationAgencyList));
	}
}
